
 cc.Class({
    extends: cc.Mask,

    properties: {

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
       this._assembler = cc.Mask._assembler;
       this._postAssembler = cc.Mask._postAssembler;
       this._super();

        this._type = cc.Mask.Type.RECT;
    },

    _activateMaterial () {
        // cc.log('_activateMaterial called!');

        let gfx = cc.gfx;
        let Material = cc.Material;

        // WebGL
        // Init material
        let material = this.sharedMaterials[0];
        if (!material) {
            material = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
        }
        else {
            material = Material.getInstantiatedMaterial(material, this);
        }

        material.define('USE_ALPHA_TEST', true);

        // Reset material
        material.define('_USE_MODEL', true);
        material.define('USE_TEXTURE', false);

        if (!this._enableMaterial) {
            this._enableMaterial = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
        }

        if (!this._exitMaterial) {
            this._exitMaterial = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
            let passes = this._exitMaterial.effect.getDefaultTechnique().passes;
            for (let i = 0; i < passes.length; i++) {
                passes[i].setStencilEnabled(gfx.STENCIL_DISABLE);
            }
        }

        if (!this._clearMaterial) {
            this._clearMaterial = Material.getInstantiatedBuiltinMaterial('clear-stencil', this);
        }

        this.setMaterial(0, material);

        this.markForRender(true);
    },

    _updateGraphics(){
        // cc.log('_updateGraphics called!');
        // let node = this.node;

        let graphics = this._graphics;
        // Share render data with graphics content
        graphics.clear(false);

        this.polyCollider = this.node.getComponent(cc.PolygonCollider);
        let points = this.polyCollider.points;
        points.forEach((point,idx)=>{
            if(idx === 0){
                graphics.moveTo(point.x,point.y);
            }else{
                graphics.lineTo(point.x,point.y);
            }
        });
        graphics.close();
        graphics.fill();
    },

});


